home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Menus / Sections / PlainMenuItem.h < prev   
Encoding:
Text File  |  1997-06-28  |  1002 b   |  52 lines  |  [TEXT/CWIE]

  1. // PlainMenuItem.h
  2.  
  3. #ifndef PlainMenuItem_h
  4. #define PlainMenuItem_h
  5.  
  6. #ifndef SingleMenuItem_h
  7. #include "SingleMenuItem.h"
  8. #endif
  9. #ifndef Commander_h
  10. #include "Commander.h"
  11. #endif
  12.  
  13. template < class TheProtocol >
  14. class PlainMenuItem: public SingleMenuItem
  15.   {
  16.     typedef TheProtocol Protocol;
  17.     typedef const Protocol ConstProtocol;
  18.     
  19.     private:
  20.         bool (ConstProtocol::*canDo)();
  21.         void (Protocol::*doIt)();
  22.         
  23.     public:
  24.         PlainMenuItem( Menu& menu, 
  25.                             void (Protocol::*toDo)(),
  26.                             bool (ConstProtocol::*canDoIt)() = 0 )
  27.           : SingleMenuItem( menu ),
  28.              canDo( canDoIt ),
  29.              doIt( toDo )
  30.           {}
  31.         
  32.         virtual void Prepare()
  33.           {
  34.             if ( Commander<Protocol>::Null() )
  35.                 Disable();
  36.              else
  37.                 if ( canDo == 0 )
  38.                     Enable();
  39.                  else
  40.                     SetEnabled( ((*Commander<Protocol>()).*canDo)() );
  41.           }
  42.         
  43.         virtual void Choose()
  44.           {
  45.             Assert( !Commander<Protocol>::Null() );
  46.             Assert( canDo == 0 || ((*Commander<Protocol>()).*canDo)() );
  47.             ((*Commander<Protocol>()).*doIt)();
  48.           }
  49.   };
  50.  
  51. #endif
  52.